<?php
/**
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     pmvc_getContextProperty
 * Purpose:  Returns a property from a 
 * -------------------------------------------------------------
 */

use pmvc\template\smarty\SmartyUtil;

function smarty_function_pmvc_getContextProperty(Array $params, &$smarty) {

	SmartyUtil::assertRequiredParameters($params, Array(
		"name"
	));
	
	$name    = $params['name'];
	$default = isset($params['default']) ? $params['default'] : null;

	// get properties lookup
	$properties = SmartyUtil::getRegisteredObject($smarty, 'ContextPropertiesLookup', true);

	// get the value
	$ret = $properties->getProperty($name, $default);

	// return it
	return SmartyUtil::returnOrAssign($smarty, $params, $ret);
}

?>